
<?php
class footerWidget extends WP_Widget
{
    function footerWidget(){
        $widget_ops = array('description' => 'Show Footer');
        $control_ops = array('width' => 200, 'height' => 250);
        parent::WP_Widget(false,$name='Footer Widget',$widget_ops,$control_ops);

    }

    //Displays the Widget in the front-end
    function widget($args, $instance){
        $before_title = $after_title =  '';
        $widget = "";
        extract($args);
        //print_r($instance);
        /*$title = apply_filters('widget_title', empty($instance['title']) ? 'Recent From ' : $instance['title']);
        if ( $title )
        {
            //echo '<h3>'. $title .'</h3>';
        }*/
        foreach($instance as $title => $name)
        {
            if($title != 'title'){

            $sub_title = '';
            $link = '#';
            $ar = array();
            if($title == 'title_download') {
                $ar[] = "Free Theme";
                $ar[] = "Free Ringtone";
                $ar[] = "Free Wallpaper";
                $ar[] = "Free TxT";
                $ar[] = "Free games";
                
            }
            if($title == 'title_upload') {
                $ar[] = "Upload Theme";
                $ar[] = "Upload Ringtone";
                $ar[] = "Upload Wallpaper";
                $ar[] = "Upload TxT";
            }
            if($title == 'title_community') {
                $ar[] = "People";
                $ar[] = "Forum";
                $ar[] = "Teams";
                $ar[] = "Groups";
            }
            if($title == 'title_mobile') {
                $ar[] = "Mobile version";
                $ar[] = "Touch version";
                $ar[] = "Android app ";
            }
            if($title == 'title_other') {
                $ar[] = "About";
                $ar[] = "Get help";
                $ar[] = "Contact Zedge";
                $ar[] = "Advertise with us";
                $ar[] = "Facebook";
            }
            if($title == 'title_legal') {
                $ar[] = "Terms of service";
                $ar[] = "Privacy policy";
                $ar[] = "Dmca/copyright";
                $ar[] = "Online safety";
                $ar[] = "Status";
            }
            foreach($ar as $link_ => $txt){
                $sub_title .= ' <li style="list-style-type: none; text-decoration: none;">
                                    <a href="'.$link.'" class="widget-footer-txt" style="text-decoration: none ! important; color: #ACACAC;text-shadow: none;">'.$txt.'</a>
                                </li>';
            }
            $widget .= '<div class="widget-footer-'.$name.' widget-footer" style="float: left; padding: 0px 0px 20px; width: 16%;">
                            <h2 class="title" style="padding-bottom: 10px;text-shadow: none;font-size:17px">'.$name.'</h2>
                            <div class="widget-footer-content">
                                '.$sub_title.'
                            </div>
                       </div>';
            }
        }
        echo $widget;
    }

    //Saves the settings.
    function update($new_instance, $old_instance){
        //die(print_r($new_instance));
        $instance = $old_instance;
        //$instance['title'] = stripslashes($new_instance['title']);
        $title_ar = array('title_download'=>'Download','title_upload' => 'Upload',
                            'title_community'=>'Community','title_mobile'=>'Mobile',
                            'title_other' => 'Other','title_legal' => 'Legal');
        foreach($title_ar as $key => $name)
        {
            $instance[$key] = stripslashes($new_instance[$key]);
        }
        //die(print_r($instance));
        return $instance;
    }

    //Creates the form for the widget in the back-end.
    function form($instance){
        $title_ar = array('title_download'=>'Download','title_upload' => 'Upload',
                            'title_community'=>'Community','title_mobile'=>'Mobile',
                            'title_other' => 'Other','title_legal' => 'Legal');
        $instance = wp_parse_args( (array) $instance,$title_ar );
        foreach($title_ar as $key => $name)
        {
            $title = esc_attr($instance[$key]);
            # Title
            echo '  <p><label for="' . $this->get_field_id($key) . '">' . 'Title:' . '</label>
                    <input class="widefat" id="' . $this->get_field_id($key) . '" name="' . $this->get_field_name($key) . '" type="text" value="' . $title. '" /></p>';
        }
    }
}

    function footerWidgetInit() {
        register_widget('footerWidget');
    }
    add_action('widgets_init', 'footerWidgetInit');




